<?php
/**
 * wp-foundation widgets.php
 */
?>
<?php

// WIDGET, ADD ABOVE HEADER
function header_above_add() {
if ( function_exists('dynamic_sidebar') && is_sidebar_active('header-above')) {
    echo '<div id="header-above" class="widget-area">';
    dynamic_sidebar('header-above');
    echo '</div><!-- eof #header-above -->';
}}
add_action('foundation_aboveheader', 'header_above_add', 8);
//END WIDGET, ADD ABOVE HEADER

// WIDGET, ADD BELOW HEADER
function header_below_add() {
if ( function_exists('dynamic_sidebar') && is_sidebar_active('header-below') ) {
    echo '<div id="header-below" class="widget-area">';
    dynamic_sidebar('header-below');
    echo '</div><!-- eof #header-below -->';
}}
add_action('foundation_belowheader', 'header_below_add', 8);
//END WIDGET, ADD BELOW HEADER

// WIDGET, ADD INSIDE HEADER DIV
function in_header_widgets_add() {
if ( function_exists('dynamic_sidebar') && is_sidebar_active('fd-in-header') ) {
    echo '<div id="fd-in-header" class="widget-area">';
    dynamic_sidebar('fd-in-header');
    echo '</div><!-- eof #fd-in-header -->';
}}
add_action('foundation_header', 'in_header_widgets_add', 8);
//END WIDGET, ADD INSIDE HEADER DIV

// WIDGET, ADD ABOVE Primary Nav DIV
function above_primary_widgets_add() {
if ( function_exists('dynamic_sidebar') && is_sidebar_active('fd-above-primary') ) {
    echo '<div id="fd-above-primary" class="widget-area">';
    dynamic_sidebar('fd-above-primary');
    echo '</div><!-- eof #fd-above_primary -->';
}}
add_action('foundation_above_primary', 'above_primary_widgets_add', 1);
//END WIDGET, ABOVE Primary Nav DIV

// WIDGET, ADD sidebar column left
function foundation_sidebar_column_left_add() {
if ( function_exists('dynamic_sidebar') && is_sidebar_active('fd-sidebar-column-left') ) {
    echo '<div id="fd-sidebar-column-left" class="widget-area">';
    dynamic_sidebar('fd-sidebar-column-left');
    echo '</div><!-- eof #fd-sidebar-column-left -->';
}}
add_action('foundation_sidebar_column_left', 'foundation_sidebar_column_left_add', 1);
//END WIDGET, sidebar column left

// WIDGET, sidebar column right
function foundation_sidebar_column_right_add() {
if ( function_exists('dynamic_sidebar') && is_sidebar_active('fd-sidebar-column-right') ) {
    echo '<div id="fd-sidebar-column-right" class="widget-area">';
    dynamic_sidebar('fd-sidebar-column-right');
    echo '</div><!-- eof #fd-sidebar-column-right -->';
}}
add_action('foundation_sidebar_column_right', 'foundation_sidebar_column_right_add', 1);
//END WIDGET, sidebar column right

// Register widgetized areas
function theme_widgets_init() {
	//above header
	register_sidebar(array(
		'name' => 'Header Above',
		'id' => 'header-above',
		'description' => 'Places a widget just above the header div.',
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));
    
	//inside header
	register_sidebar(array(
		'name' => 'Inside Header',
		'id' => 'fd-in-header',
		'description' => 'Places a widget inside the header and above the top nav.',
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));
    
	//Below Header
	register_sidebar(array(
		'name' => 'Header Below',
		'id' => 'header-below',
		'description' => 'Places a widget just below the header div.',
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));
	    
	//Above Primary
	register_sidebar(array(
		'name' => 'Above Primary',
		'id' => 'fd-above-primary',
		'description' => 'Places a widget above the primary nav with hook.',
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));
	
	//Primary
	register_sidebar( array (
		'name' => 'Primary Widget Area',
		'id' => 'primary-widget-area',
		'description' => 'Primary side widget.',
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));
	
	//Secondary
	register_sidebar( array (
		'name' => 'Secondary Widget Area',
		'id' => 'secondary-widget-area',
		'description' => 'Secondary side widget.',
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => "</li>",
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));
	  
	//column left
	register_sidebar(array(
		'name' => 'Sidebar Column Left',
		'id' => 'fd-sidebar-column-left',
		'description' => 'Widget for left column in sidebar.',
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));
	
	//column right
	register_sidebar(array(
		'name' => 'Sidebar Column Right',
		'id' => 'fd-sidebar-column-right',
		'description' => 'Widget for right column in sidebar.',
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => "</li>",
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));
  
} // end theme_widgets_init
add_action( 'init', 'theme_widgets_init' );

// Check for static widgets in widget-ready areas
function is_sidebar_active( $index ){
  global $wp_registered_sidebars;
  $widgetcolums = wp_get_sidebars_widgets();	 
  if ($widgetcolums[$index]) return true;
	return false;
} // end is_sidebar_active





add_action('foundation_widget_footer_stuff', 'foundation_footer_widget_add');
add_action( 'init', 'footer_widgets_init'); 


function foundation_footer_widget_add($options) {
foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}
	if($fd_footer_widget_area_enable == 'Enable'){
		for($i=1; $i<($fd_footer_widget_area_number+1); $i++){	
			if ( function_exists('dynamic_sidebar') && is_sidebar_active('foundation-footer-widget-' . $i)) 
			{
				echo '<div id="foundation_footer_widget_' . $i . '" class="widget-area">';
				dynamic_sidebar('foundation-footer-widget-' . $i);
				echo '</div><!-- eof #foundation_footer_widget_' . $i . ' -->';
			}
		}
	}
}
					
function footer_widgets_init() {
	global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}
	for($i=1; $i<($fd_footer_widget_area_number+1); $i++){
		register_sidebar(array(
			'name' => 'Footer Widget ' . $i,
			'id' => 'foundation-footer-widget-' . $i,
			'description' => 'Places a widget in the footer area.',
			'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		));
	}
}
?>